package com.yuerlive.paperplane.timeline;

import android.support.annotation.NonNull;

import com.yuerlive.paperplane.data.ZhihuDailyNewsQuestion;
import com.yuerlive.paperplane.data.source.datasource.ZhihuDailyNewsDataSource;
import com.yuerlive.paperplane.data.source.repository.ZhihuDailyNewsRepository;

import java.util.List;

/**
 * Created by Admin on 2017/10/12.
 */

public class ZhihuDailyPresenter implements ZhihuDailyContract.Presenter {
    @NonNull
    private ZhihuDailyContract.View view;
    private ZhihuDailyNewsRepository mRepository;
    public ZhihuDailyPresenter(@NonNull ZhihuDailyContract.View view,@NonNull ZhihuDailyNewsRepository respository){
       this.view =view ;
        this.mRepository =respository;
        this.view.setPresenter(this);
    }
    @Override
    public void start() {

    }

    @Override
    public void loadNews(boolean forceUpdate, boolean clearCache, long date) {
      mRepository.getZhihuDailyNews(forceUpdate, clearCache, date, new ZhihuDailyNewsDataSource.loadZhihuDailyNewsCallback() {
       @Override
       public void onNewsLoad(@NonNull List<ZhihuDailyNewsQuestion> list) {
           if(view.isActive()){
               view.showResult(list);
               view.setLoadingIndicator(false);
           }
       }

       @Override
       public void onDataNotAvailable() {
           if (view.isActive()) {
               view.setLoadingIndicator(false);
           }
       }
   });
    }
}
